package com.cy.seller.service;

import com.cy.api.ProductRpc;
import com.cy.api.domain.ProductRpcReq;
import com.cy.entity.Product;
import com.cy.entity.enums.ProductStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ProductRpcService
 * @Deserintion 产品服务
 * @Author ciyuan
 * @Date 2018/12/5/005 0:41
 **/
@Slf4j
@Service
public class ProductRpcService {

    @Autowired
    private ProductRpc productRpc;

    /**
     * 查询全部产品
     * @return
     */
    public List<Product> findAll(){
        ProductRpcReq req = new ProductRpcReq();
        List<String> status = new ArrayList<>();
        status.add(ProductStatus.IN_SELL.name());
        req.setStatusList(status);
        log.info("RPC请求查询全部产品，请求=【{}】", req);
        List<Product> result = productRpc.query(req);
        log.info("RPC请求查询全部产品，结果=【{}】",result);
        return result;
    }

    /**
     * 测试 findAll() 方法
     */
    @PostConstruct
    public void testFindAll(){
        findAll();
    }
}
